<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:PlanetWPF.Toolbelt.Controls"
    >

  <DataTemplate x:Key="GridViewTemplate">
    <local:PowerGridRow 
      Columns="{Binding 
                RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type local:PowerGridView}},
                Path=Columns}"
    ParentGrid="{Binding 
                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PowerGridView}},
                Path=ParentGrid}" 
      Item="{Binding}"
      >
    </local:PowerGridRow>
  </DataTemplate>
  <Style x:Key="ViewScroller"
                 TargetType="{x:Type ItemsControl}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ItemsControl}">
          <ScrollViewer 
            CanContentScroll="True" 
            Height="400">
            <VirtualizingStackPanel IsVirtualizing="True" ScrollViewer.VerticalScrollBarVisibility="Auto" 
                                    Orientation="Vertical"
                                    IsItemsHost="True"/>
          </ScrollViewer>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type local:PowerGridView}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:PowerGridView}">
          <ItemsControl Name="PART_ItemsControl"
                      Margin="0,0,0,0" 
                      Style="{StaticResource ViewScroller}" 
                      ItemTemplate="{StaticResource GridViewTemplate}"
                      ItemsSource="{TemplateBinding Items}"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>